

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busFiles:BusinessBase
	{
		public busFiles() : base()
		{
		}
		#region  Code Factory Generated Methods

		public DataTable SelectFiles()
		{
			try
			{
				datFiles insDatFiles = new datFiles();
				DbConnector insDbConnector = new DbConnector();
				return insDatFiles.SelectFiles(insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage = ex.Message;
			}
			return null;
		}
		public void SelectFilesByFileId(entFiles parEntFiles)
		{
			try
			{
				datFiles insDatFiles = new datFiles();
				DbConnector insDbConnector = new DbConnector();
				insDatFiles.SelectFilesByFileId(parEntFiles, insDbConnector);
			}
			catch (SFException ex)
			{
				this.ErrorMessage=ex.Message;
			}
		}
		
		#endregion
        public void InsertFiles(entFiles parEntFiles)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datFiles insDatFiles = new datFiles();
                insDatFiles.InsertFiles(parEntFiles, insDbConnector);
                datFilesContents insDatFilesContents = new datFilesContents();
                foreach (entFilesContents insEntFilesContents in parEntFiles.FilesContentsInsert)
                {
                    insEntFilesContents.FileId = parEntFiles.FileId;
                    insDatFilesContents.InsertFilesContents(insEntFilesContents, insDbConnector);
                }
                foreach (entFilesContents insEntFilesContents in parEntFiles.FilesContentsUpdate)
                {
                    insEntFilesContents.FileId = parEntFiles.FileId;
                    insDatFilesContents.UpdateFilesContentsByFilesContentId(insEntFilesContents, insDbConnector);
                }
                foreach (entFilesContents insEntFilesContents in parEntFiles.FilesContentsDelete)
                {
                    insDatFilesContents.DeleteFilesContentsByFilesContentId(insEntFilesContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void UpdateFilesByFileId(entFiles parEntFiles)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datFiles insDatFiles = new datFiles();
                insDatFiles.UpdateFilesByFileId(parEntFiles, insDbConnector);
                datFilesContents insDatFilesContents = new datFilesContents();
                foreach (entFilesContents insEntFilesContents in parEntFiles.FilesContentsInsert)
                {
                    insEntFilesContents.FileId = parEntFiles.FileId;
                    insDatFilesContents.InsertFilesContents(insEntFilesContents, insDbConnector);
                }
                foreach (entFilesContents insEntFilesContents in parEntFiles.FilesContentsUpdate)
                {
                    insEntFilesContents.FileId = parEntFiles.FileId;
                    insDatFilesContents.UpdateFilesContentsByFilesContentId(insEntFilesContents, insDbConnector);
                }
                foreach (entFilesContents insEntFilesContents in parEntFiles.FilesContentsDelete)
                {
                    insDatFilesContents.DeleteFilesContentsByFilesContentId(insEntFilesContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void DeleteFilesByFileId(entFiles parEntFiles)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDbConnector.BeginTransaction();

                datFilesContents insDatFilesContents = new datFilesContents();
                entFilesContents insEntFilesContents = new entFilesContents();
                insEntFilesContents.FileId = parEntFiles.FileId;
                insDatFilesContents.DeleteFilesContentsByFileId(insEntFilesContents, insDbConnector);

                datFiles insDatFiles = new datFiles();
                insDatFiles.DeleteFilesByFileId(parEntFiles, insDbConnector);

                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public DataTable SelectFilesLatest()
        {
            try
            {
                datFiles insDatFiles = new datFiles();
                DbConnector insDbConnector = new DbConnector();
                return insDatFiles.SelectFilesLatest(insDbConnector);

            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public DataTable SelectFilesByLanguageId()
        {
            try
            {
                datFiles insDatFiles = new datFiles();
                DbConnector insDbConnector = new DbConnector();
                return insDatFiles.SelectFilesByLanguageId(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
	}
}